package com.aktiehuis.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.aktiehuis.main.Klant;
import com.aktiehuis.main.Product;
import com.aktiehuis.main.Winkel;

@Table(name="winkels")
@Entity
public class WinkelBean implements Winkel, Serializable {
	private static final long serialVersionUID = 5696458841758808801L;
	@Id @GeneratedValue private int id = 0;
	private String naam = null;
	@OneToMany(targetEntity=ProductBean.class, mappedBy="winkel", fetch=FetchType.EAGER)
	private List<Product> producten = null;
	@Transient
	private List<Klant> klanten = null;
	
	public WinkelBean() {
		id = 0;
		naam = null;
		producten = new ArrayList<Product>();
		klanten = new ArrayList<Klant>();
	}
	
	public WinkelBean( int newId, String newNaam ) {
		id = newId;
		naam = newNaam;
		producten = new ArrayList<Product>();
		klanten = new ArrayList<Klant>();
	}
	
	public int getId() {
		return id;
	}
	
	public String getNaam() {
		return naam;
	}
	
	public List<Product> getProducten() {
		return producten;
	}
	
	public void voegToe( Product product ) {
		producten.add( product );
	}
	
	public void verwijder( Product product ) {
		producten.remove( product );
	}
	
	public void enter( Klant klant ) {
		klanten.add( klant );
	}
	
	public void verlaat( Klant klant ) {
		klanten.remove( klant );
	}
	
	public List<Klant> getKlanten() {
		return klanten;
	}
}
